<template>
  <view class="result-page">
    <view class="result-content">
      <view class="result-title">藏品信息</view>
      <view class="result-info">
        <view class="info-list">
          <view class="list-title">鉴宝人</view>
          <view class="list-nav">
            <image :src="listData.expert?listData.expert.avatar:''" mode="" class="info-avatar"></image>
            {{listData.expert?listData.expert.nickname:''}}
          </view>
        </view>
        <view class="info-list">
          <view class="list-title">藏品类型</view>
          <view class="list-nav">
            <image :src="listData.category?listData.category.image:''" mode="" class="info-avatar"></image>
            {{listData.category?listData.category.name:''}}
          </view>
        </view>
        <view class="info-list">
          <view class="list-title">是否公开</view>
          <view class="list-nav">{{listData.is_open ===1?'公开鉴定':'未公开鉴定'}}</view>
        </view>
        <view class="info-list">
          <view class="list-title">藏品描述</view>
          <view class="list-nav">{{listData.desc}}</view>
        </view>
        <view class="info-list">
          <view class="list-title">提交时间</view>
          <view class="list-nav">{{listData.create_time}}</view>
        </view>
      </view>
      <view class="result-imgs">
        <view class="img-title">鉴别外观</view>
        <view class="img-amplify">
          <up-image :src="srcActive" radius="16rpx" width="630rpx" height="630rpx" :lazy-load="true" mode="aspectFit"
            v-if="!saskShow" @click="onAmplifyImg(srcActive,'image')"></up-image>
          <DomVideoPlayer ref="domVideoPlayer" :src="srcActive" controls isLoading muted class="video-nav" v-else @click="onAmplifyImg(srcActive,'video')"/>
        </view>
        <view class="img-list">
          <view class="list-img" v-show="listData.vedio" @click="ontaskImage(listData.vedio,'vedio')">
            <DomVideoPlayer ref="domVideoPlayer" :src="listData.vedio" muted class="info-video" />
            <image src="@/static/home/icon/play.png" mode="aspectFill" class="vedio-icon"></image>
          </view>
          <view class="list-img" v-for="item,index in listData.task_image" :key="index"
            @click="ontaskImage(item.image,'image')">
            <up-image :src="item.image" radius="16rpx" width="128rpx" height="128rpx" mode="aspectFit"
              :lazy-load="true"></up-image>
          </view>
        </view>
      </view>
      <view class="content-title">
        <view class="result-title">鉴定结果</view>
        <view class="result-label">根据用户提供的信息得出，给出鉴定结果</view>
      </view>
      <view class="result-user">
        <view class="result-option">
          <view class="option-title">鉴定结果 <view style="color: #F52020;">*</view>
          </view>
          <up-radio-group v-model="radiovalue" placement="row" activeColor="#A4682F" @change="groupChange">
            <up-radio :customStyle="{marginBottom: '8px'}" v-for="(item, index) in radiolist" :key="index"
              :label="item.name" :name="item.name">
            </up-radio>
          </up-radio-group>
        </view>
        <view class="result-according">
          <view class="according-title">判断依据 <view style="color: #F52020;">*</view>
          </view>
          <up-textarea v-model="accordingValue" border="none" placeholder="请根据用户提供的信息得出，给出你对鉴定藏品的判断依据"></up-textarea>
        </view>
      </view>
      <view class="result-btn">
        <up-button text="提交鉴定结果" shape="circle" color="#A4682F" @click="taskSubmitApi"></up-button>
      </view>
    </view>
  </view>
  <up-modal :show="modalShow" title="鉴定成功" confirmText="我知道了" contentTextAlign="center" confirmColor="#A4682F"
    content='我们尽快将您的鉴定结果发送给用户' @confirm="onconfirm"></up-modal>
</template>

<script setup>
  import {
    taskInfo,
    taskSubmit
  } from './api.js'
  import {
    ref
  } from 'vue'
  import {
    onLoad
  } from '@dcloudio/uni-app'
  import DomVideoPlayer from '@/components/DomVideoPlayer/DomVideoPlayer';
  const taskId = ref()
  const listData = ref({})
  const srcActive = ref('')
  const accordingValue = ref('')
  const radiovalue = ref('')
  const radioId = ref()
  const modalShow = ref(false)
  const saskShow = ref()
  const radiolist = ref([{
      name: '真品',
      id: 1,
      disabled: false,
    },
    {
      name: '赝品',
      id: -1,
      disabled: false,
    },
    {
      name: '存疑',
      id: 2,
      disabled: false,
    }
  ]);
  onLoad((e) => {
    if (e && e.id) {
      taskId.value = e.id
      taskInfoAPi(e.id)
    }
  })

  function ontaskImage(url, type) {
    saskShow.value = type == 'image' ? false : true
    srcActive.value = url
  }
  //全屏查看
  function onAmplifyImg(url, type) {
    uni.navigateTo({
      url: `/pages/index/fullScreenPreview/FullScreenPreview?type=${type}&src=${url}`
    })
  }
  const taskInfoAPi = (async (id) => {
    const res = await taskInfo({
      task_id: id
    })
    if (res && res.code === 1) {
      listData.value = res.data
      srcActive.value = res.data.vedio ? res.data.vedio : res.data.task_image[0].image
      saskShow.value = res.data.vedio ? true : false
    } else {
      uni.showToast({
        title: res.msg,
        icon: 'none'
      })
    }
  })
  const taskSubmitApi = (async () => {
    if (!radioId.value) {
      uni.showToast({
        title: '请选择鉴定结果',
        icon: 'none'
      })
      return
    }
    if (!accordingValue.value) {
      uni.showToast({
        title: '请输入判断依据',
        icon: 'none'
      })
      return
    }
    const res = await taskSubmit({
      task_id: taskId.value,
      label: radioId.value,
      decide: accordingValue.value
    })
    if (res && res.code === 1) {
      modalShow.value = true
    } else {
      uni.showToast({
        title: res.msg,
        icon: 'none'
      })
    }
  })

  function groupChange(e) {
    radiovalue.value = e
    radioId.value = e == '真品' ? 1 : e == "赝品" ? -1 : 2
  }

  function onconfirm() {
    uni.navigateBack(-1)
  }
</script>

<style lang="scss" scoped>
  .result-page {
    background-color: #F2F2F2;
    display: flex;
    flex-direction: column;
    height: 100%;


    ::v-deep .u-navbar--fixed {
      position: sticky;
      box-sizing: border-box;
      background-color: #fff;
    }

    .result-content {
      display: flex;
      flex-direction: column;
      box-sizing: border-box;
      padding: 0 30rpx 156rpx;
      flex: 1;
      overflow: scroll;

      .content-title {
        display: flex;
      }

      .result-label {
        font-size: 24rpx;
        font-weight: 400;
        color: rgba(153, 153, 153, 1);
        margin: 48rpx 0 0 16rpx;
      }

      .result-user {
        margin-top: 30rpx;
        width: 100%;
        border-radius: 16rpx;
        background: rgba(255, 255, 255, 1);
        box-sizing: border-box;
        padding: 0 30rpx 30rpx;

        .result-option {
          display: flex;
          width: 100%;
          height: 88rpx;
          border-bottom: 2rpx solid rgba(235, 235, 235, 1);
          align-items: center;

          .option-title {
            font-size: 28rpx;
            font-weight: 400;
            color: rgba(51, 51, 51, 1);
            display: flex;
            margin-right: 30rpx;
          }

          ::v-deep .u-radio {
            flex: 1;
          }
        }

        .result-according {
          display: flex;
          flex-direction: column;
          margin-top: 24rpx;

          ::v-deep .u-textarea {
            background-color: #F2F2F2;
            border-radius: 16rpx;
            margin-top: 24rpx;
          }

          .according-title {
            font-size: 28rpx;
            font-weight: 400;
            color: rgba(51, 51, 51, 1);
            display: flex;
          }
        }
      }

      .result-imgs {
        width: 690rpx;
        border-radius: 16rpx;
        background: #FFFFFF;
        margin-top: 24rpx;
        box-sizing: border-box;
        padding: 30rpx;

        .img-title {
          font-size: 28rpx;
          font-weight: 400;
          color: rgba(153, 153, 153, 1);

        }

        .img-amplify {
          width: 630rpx;
          height: 630rpx;
          border-radius: 16rpx;
          margin-top: 24rpx;

          .video-nav {
            width: 630rpx;
            height: 630rpx;
          }
        }

        .img-list {
          display: flex;
          margin-top: 24rpx;
          overflow: scroll;

          .list-img {
            width: 128rpx;
            height: 128rpx;
            border-radius: 16rpx;
            flex: 0 0 auto;
            margin-right: 16rpx;
            border: 2rpx solid rgba(235, 235, 235, 1);
            position: relative;

            .vedio-icon {
              height: 48rpx;
              width: 48rpx;
              position: absolute;
              top: 50%;
              left: 50%;
              transform: translate(-50%, -50%);
            }
          }
        }
      }

      .result-info {
        width: 690rpx;
        border-radius: 16rpx;
        background: #FFFFFF;
        box-sizing: border-box;
        padding: 0 30rpx 30rpx;
        margin-top: 30rpx;

        .info-list {
          display: flex;
          margin-top: 30rpx;

          .list-title {
            width: 30%;
            font-size: 28rpx;
            font-weight: 400;
            color: rgba(153, 153, 153, 1);

          }

          .list-nav {
            flex: 1;
            font-size: 28rpx;
            font-weight: 400;
            color: rgba(51, 51, 51, 1);
            display: flex;
            align-items: center;

            .info-avatar {
              width: 40rpx;
              height: 40rpx;
              border-radius: 50%;
              margin-right: 12rpx;
            }
          }
        }
      }

      .result-btn {
        width: 690rpx;
        position: fixed;
        bottom: 12rpx;
        height: 88rpx;
        border-radius: 44rpx;
        background: $color;
        display: flex;
        align-items: center;
        z-index: 1;
      }

      .result-title {
        font-size: 34rpx;
        font-weight: 500;
        color: rgba(51, 51, 51, 1);
        margin-top: 40rpx;
        position: relative;
        width: max-content;
        z-index: 1;
        display: flex;
      }

      .result-title:before {
        content: "";
        width: 100%;
        height: 16rpx;
        opacity: 0.5;
        background: linear-gradient(90deg, $color 0%, transparent 100%);
        position: absolute;
        bottom: 0;
        left: 0;
        z-index: 0;
      }
    }
  }
</style>